var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), e = require("../../../@babel/runtime/helpers/defineProperty"), a = t(require("../../../utils/util")), s = getApp(), o = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ o ],
    data: {
        search: "",
        screenShow: !1,
        goodsList: [],
        cakeType: [ {
            type: "",
            text: "全部"
        }, {
            type: 1,
            text: "4-5人食"
        }, {
            type: 2,
            text: "6-9人"
        }, {
            type: 3,
            text: "10-12人"
        }, {
            type: 4,
            text: "12人以上"
        } ],
        getBrand: [],
        query: {
            page: 1,
            city: "",
            order_field: "",
            order_by: "",
            cake_type: "",
            cake_price_max: "",
            cake_price_min: "",
            snacks_price_max: "",
            snacks_price_min: ""
        },
        totalPage: 0,
        isLoadMore: !0,
        brandsId: "",
        categorysId: "",
        keyword: "",
        priceSnacks: [ {
            type: [ "", "" ],
            text: "全部"
        }, {
            type: [ 20, 99 ],
            text: "20-99"
        }, {
            type: [ 100, 199 ],
            text: "100-199"
        }, {
            type: [ 199, "" ],
            text: "199以上"
        } ],
        cakePriceArr: [ {
            type: [ "", "" ],
            text: "全部"
        }, {
            type: [ 100, 200 ],
            text: "100-200"
        }, {
            type: [ 200, 300 ],
            text: "200-300"
        } ],
        categorys: [],
        indexType: 0
    },
    onLoad: function(t) {
        t.city && this.setData({
            "query.city": t.city
        });
    },
    goodsByList: function() {
        var t = this, e = s.getNetAddresss("plugin.yz-supply-cake.frontend.goods.goods.getGoodsList");
        e += "&search[brand_id]=".concat(this.data.brandsId), e += "&search[category]=".concat(this.data.categorysId), 
        e += "&search[keyword]=".concat(this.data.keyword), s._getNetWork({
            url: e,
            data: this.data.query,
            success: function(e) {
                var a = e.data;
                wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 1 == a.result ? (t.data.totalPage = a.data.last_page, 
                t.data.totalPage || (t.data.totalPage = 0), t.setData({
                    goodsList: a.data.data
                })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.query.page >= this.data.totalPage)) {
            this.data.query.page = this.data.query.page + 1;
            var e = s.getNetAddresss("plugin.yz-supply-cake.frontend.goods.goods.getGoodsList");
            e += "&search[brand_id]=".concat(this.data.brandsId), e += "&search[category]=".concat(this.data.categorysId), 
            e += "&search[keyword]=".concat(this.data.keyword), s._getNetWork({
                url: e,
                data: this.data.query,
                success: function(e) {
                    var a = e.data, s = a.data.data;
                    1 == a.result ? (t.data.isLoadMore = !0, t.setData({
                        goodsList: t.data.goodsList.concat(s)
                    })) : (t.data.query.page = t.data.query.page - 1, t.data.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    screenClick: function(t) {
        var e = t.detail, a = e.brandValue, s = e.cakeValue, o = e.categoryValue, i = e.priceValue, r = e.cakePirceValue;
        this.setData({
            screenShow: !1,
            isLoadMore: !0,
            brandsId: a,
            categorysId: o,
            "query.cake_type": s,
            "query.page": 1,
            "query.cake_price_min": r[0],
            "query.cake_price_max": r[1],
            "query.snacks_price_min": i[0],
            "query.snacks_price_max": i[1]
        }), this.goodsByList();
    },
    popularity: function() {
        this.setData({
            "query.order_field": "popularity",
            "query.order_by": "",
            "query.page": 1,
            isLoadMore: !0
        }), this.goodsByList();
    },
    salesClick: function(t) {
        var e = t.currentTarget.dataset.sort;
        this.sortSwicth(e, "asc", "show_sales");
    },
    sortSwicth: function(t, e, a) {
        switch (t) {
          case "asc":
            e = "desc";
            break;

          case "desc":
            e = "asc";
        }
        this.setData({
            "query.page": 1,
            "query.order_by": e,
            "query.order_field": a,
            isLoadMore: !0
        }), this.goodsByList();
    },
    searchOn: function(t) {
        var e = this;
        this.setData({
            keyword: t.detail
        }), this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
            a.default.debounce(e.goodsByList());
        }, 500);
    },
    priceClick: function(t) {
        var e = t.currentTarget.dataset.sort;
        this.sortSwicth(e, "asc", "price");
    },
    brandClick: function(t) {
        var a = t.detail.id;
        this.setData(e({}, "search.brand_id", a));
    },
    screeningPopup: function() {
        this.setData({
            screenShow: !0
        });
    },
    getBrandsData: function() {
        var t = this, e = {
            city: this.data.query.city
        }, a = s.getNetAddresss("plugin.yz-supply-cake.frontend.goods.goods.getBrand");
        s._getNetWork({
            url: a,
            data: e,
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    getBrand: a.data
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    categorysList: function() {
        var t = this, e = s.getNetAddresss("plugin.yz-supply-cake.frontend.index.index.getCategorys");
        s._getNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    categorys: a.data
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {
        var t = this;
        try {
            this._getLocation(function(e, a) {
                var s = e.address_component.city;
                t.data.query.city || t.setData({
                    "query.city": s
                }), t.categorysList(), t.goodsByList(), t.getBrandsData();
            });
        } catch (t) {
            console.log(t), this.categorysList(), this.goodsByList(), this.getBrandsData();
        }
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {}
});